package animationGame;

public class Vertex {
	
	public double x;
	public double y;
	
	public Vertex(double x, double y){
		this.x = x;
		this.y = y;
	}
	
	public double getX(){
		return x;
	}
	
	public void setX(double x){
		this.x = x;
	}
	
	public double getY(){
		return y;
	}
	
	public void setY(double y){
		this.y = y;
	}
	
	public String toString(){
		return "("+x+","+y+")";
	}
	
	public double length(){
		return Math.sqrt(x*x+y*y);
	}
	
	public Vertex skalarMult(double s){
		return new Vertex(x*s, y*s);
	}
	
	public void skalarMultMod(double s){
		x = x*s;
		y = y*s;
	}
	
	public Vertex add(Vertex v2){
		return new Vertex(v2.getX()+x,v2.getY()+y);
	}
	
	public void addMod(Vertex v2){
		x = x+v2.getX();
		y = y+v2.getY();
	}
	
	public boolean equals(Object thatObject){
		if(thatObject instanceof Vertex){
			Vertex that = (Vertex)thatObject;
			return this.x==that.getX()&&this.y==that.getY();
		}else{
			return false;
		}
	}
	
	public Vertex sub(Vertex that){
		return new Vertex(this.x-that.getX(),this.y-that.getY());
	}
	
	public double distance(Vertex that){
		double x1, y1;
		x1 = this.x - that.getX();
		y1 = this.y - that.getY();
		return Math.sqrt(x1*x1+y1*y1);
	}
	
	public Vertex normalized(){
		return this.skalarMult(1/this.length());
	}
}
